import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class POI {
	
	/*	
	public static void main(String[] args) {
			try {
				FileInputStream fileInputStream = new FileInputStream("Kowalski_Jan.xls");
				HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
				HSSFSheet worksheet = workbook.getSheet("Projekt1");
				HSSFRow row1 = worksheet.getRow(0);
				HSSFCell cellA1 = row1.getCell((short) 0);
				String a1Val = cellA1.getStringCellValue();
				HSSFCell cellB1 = row1.getCell((short) 1);
				String b1Val = cellB1.getStringCellValue();
				HSSFCell cellC1 = row1.getCell((short) 2);
				String c1Val = cellC1.getStringCellValue();
				
				System.out.println("A1: " + a1Val);
				System.out.println("B1: " + b1Val);
				System.out.println("C1: " + c1Val);
			
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		*/
	
	/*
	public static void main(String[] args)
    {
        try
        {
            FileInputStream file = new FileInputStream(new File("Kowalski_Jan.xlsx"));
 
            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);
 
            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);
 
            //Iterate through each rows one by one
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext())
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();
                 
                while (cellIterator.hasNext())
                {
                    Cell cell = cellIterator.next();
                    //Check the cell type and format accordingly
                    switch (cell.getCellType())
                    {
                        case Cell.CELL_TYPE_NUMERIC:
                        	if (DateUtil.isCellDateFormatted(cell)) {
                                System.out.println(cell.getDateCellValue());
                            } else {
                                System.out.println(cell.getNumericCellValue());
                            }
                            break;
                        case Cell.CELL_TYPE_STRING:
                            System.out.print(cell.getStringCellValue() + "   ");
                            break;
                    }
                }
                System.out.println("");
            }
            file.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
*/
	
	public static void main(String[] args) {
		try {
			FileInputStream file = new FileInputStream(new File(
					"Kowalski_Jan3.xlsx"));

			// Create Workbook instance holding reference to .xlsx file
			XSSFWorkbook workbook = new XSSFWorkbook(file);

			// Get first/desired sheet from the workbook
			XSSFSheet sheet = workbook.getSheetAt(0);

			// Iterate through each rows one by one
			Iterator<Row> rowIterator = sheet.iterator();
			rowIterator.next(); // omit header
			while (rowIterator.hasNext()) {
				Row row = rowIterator.next();
				// For each row, iterate through all the columns
				Iterator<Cell> cellIterator = row.cellIterator();
				if (row.getCell(0)!= null) {
				System.out.println(row.getCell(0).getDateCellValue());
				}
				if (row.getCell(1) != null){
				System.out.println(row.getCell(1).getStringCellValue());
				}
				if (row.getCell(2) != null){
				System.out.println(row.getCell(2).getNumericCellValue());
				}
				System.out.println("");
			}
			file.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

	
	

